Feed = {
	current : 0,
	level : 0,
	ownerId : 0,
	getFeedsUrl : SKYLINE_DOMAIN + "feed/list.html",
	getMyFeedsUrl : SKYLINE_DOMAIN + "feed/listMyFeeds.html",
	getNewFeedsUrl : SKYLINE_DOMAIN + "feed/getNewFeeds.html",
	newFeedTimmerInterval : 6000,
	newFeedsNum : 0,
	getFeeds : function() {
		$.ajax({
					url : this.getFeedsUrl,
					data : "ownerId=" + Feed.ownerId + "&current="
							+ Feed.current + "&level=" + Feed.level,
					type : "POST",
					dataType : "json",
					contentType : "application/x-www-form-urlencoded;charset=utf-8",
					success : function(result) {
						Feed.level = result.level;
						Feed.current = result.current;
						if (result.data == null || result.data.length == 0) {
							// jAlert("对不起,没有更多新鲜事。", '新鲜事');
							$("#feedMessage").html(
									"<font color='red'>对不起,没有更多新鲜事。</font>");
						} else {
							Feed.level = result.level;
							Feed.current = result.current;
							var innerHTML = "";
							for ( var i = 0; i < result.data.length; i++) {
								// var feedData = result.data[i];
								innerHTML += Feed.genFeed(result.data[i]);
							}
							$("#feedsDiv")[0].innerHTML += innerHTML;
						}
					},
					error : function() {
						$("#feedMessage").html(
								"<font color='red'>对不起,获取新鲜事失败。</font>");
					}
				});
	},
	getFeedsInitial:function(ownerId){
		Feed.ownerId=ownerId;
		Feed.getFeeds();
	},
	getFeedComment : function(resourceName, type, resourceId, ownerId) {
		var showA = $("#feedComment" + resourceId + "Show")[0];
		if (showA.innerHTML != "收起评论") {
			if ($("#feedComment" + resourceId)[0].innerHTML == "") {
				$("#feedComment" + resourceId)[0].innerHTML = "<hr>";
				var script = AjaxComment.generateAllscript("feed" + resourceId,
						resourceId, resourceName, type, ownerId);
				// $("#feedComment" + resourceId)[0].innerHTML +="<script
				// type=\"text/javascript\">"+script+"</script>";
				$("#feedComment" + resourceId)[0].innerHTML += AjaxComment
						.generateAllHTML("feed" + resourceId, resourceId,
								resourceName, type, ownerId);

				// alert(AjaxComment.generateAllscript("feed"+resourceId,resourceId,resourceName,type,ownerId));
				eval(script);
			}
			$("#feedComment" + resourceId).show();
			showA.innerHTML = "收起评论";
		} else {
			$("#feedComment" + resourceId).hide();
			showA.innerHTML = "评论";
		}
	},
	getMyFeedsInitial : function() {
		 newFeedTimmer=setInterval("Feed.getNewFeeds()",Feed.newFeedTimmerInterval);
		Feed.getMyFeeds();
	},
	getMyFeeds : function() {
		$.ajax({
			url : this.getMyFeedsUrl,
			data : "current=" + Feed.current + "&level=" + Feed.level,
			type : "POST",
			dataType : "json",
			contentType : "application/x-www-form-urlencoded;charset=utf-8",
			success : function(result) {
				if (result == null || result.data == null
						|| result.data.length == 0) {
					// jAlert("对不起,没有更多新鲜事。", '新鲜事');
					$("#feedMessage").html(
							"<font color='red'>对不起,没有更多新鲜事。</font>");
				} else {
					Feed.level = result.level;
					Feed.current = result.current;
					var innerHTML = "";
					for ( var i = 0; i < result.data.length; i++) {
						// var feedData = result.data[i];
						innerHTML += Feed.genFeed(result.data[i]);
					}
					$("#feedsDiv")[0].innerHTML += innerHTML;
				}
			},
			error : function() {
				jAlert("对不起,获取新鲜事失败。", '新鲜事');
			}
		});
	},
	genFeed : function(feedData) {
		var innerHTML = "";
		innerHTML += "<table><tr><td rowspan='3' valign='top' width='72px' align='center'><img src='"
				+ portraitPath
				+ feedData.pp
				+ "' class='portraitMin'></td><td colspan='2'><a href=''>"
				+ feedData.pnn + "</a>&nbsp;";
		if (feedData.tp == "ARTICLE") {
			innerHTML += "发表日志&nbsp;<a href='" + SKYLINE_DOMAIN
					+ "article/view/" + feedData.rid + ".html'>" + feedData.tit
					+ "</a></td></tr>";
			innerHTML += "<tr><td colspan='2'><p>" + feedData.con
			+ "</p></td></tr>";
		}else if (feedData.tp == "VIDEO") {
			innerHTML += "分享视频&nbsp;<a href='" + SKYLINE_DOMAIN
				+ "video/view/" + feedData.rid + ".html'>" + feedData.tit
				+ "</a></td></tr>";
			innerHTML += "<tr><td colspan='2'><p>" + feedData.con
				+ "</p></td></tr>";
			//alert(feedData.con);
		}  else if (feedData.tp == "SHORTMESSAGE") {
			innerHTML += "发表&nbsp;<a href='" + SKYLINE_DOMAIN
					+ "shortMessage/id/" + feedData.rid
					+ ".html'>短消息</a></td></tr>";
			for ( var i = 0; i < smileys.length; i++) {
				var reg = "/" + smileys[i];
				var rep = "<img lt='" + smileysChn[i] + "' src='" + smileysPath
						+ smileys[i] + ".gif'>";
				 feedData.con =  feedData.con.replaceAll(reg, rep);
			}
			innerHTML += "<tr><td colspan='2'><p>" + feedData.con
			+ "</p></td></tr>";
		}
		
		var date = new Date(feedData.t);
		innerHTML += "<tr><td width='660px' align='left'>发表于:"
				+ date.format("yyyy-MM-dd hh:mm:ss") + "</td>";
		innerHTML += "<td width='120px' align='right'>";
		if (feedData.tp == "SHORTMESSAGE") {
			innerHTML+="<a href='javascript:ShortMessage.forwardShortMessageRequest("+feedData.rid +")'>转发</a>|";
		}
		innerHTML +="<a id=\"feedComment"
				+ feedData.rid
				+ "Show\" href='javascript:Feed.getFeedComment(\""
				+ feedData.tit + "\",\"" + feedData.tp + "\"," + feedData.rid
				+ "," + feedData.oid + ")'>评论</a>";
		innerHTML += "</td></tr>";
		innerHTML += "<tr><td align='right' colspan='3' id=\"feedComment"
				+ feedData.rid
				+ "\" style='display:none'></td></tr></table><hr>";
		return innerHTML;
	},
	getNewFeeds : function() {
		$
				.ajax({
					url : this.getNewFeedsUrl,
					data : null,
					type : "POST",
					dataType : "json",
					contentType : "application/x-www-form-urlencoded;charset=utf-8",
					success : function(result) {
						// alert(result);
						if (result == null || result.length == 0) {
							// jAlert("对不起,没有更多新鲜事。", '新鲜事');
						} else {
							// alert();
							Feed.newFeedsNum += result.length;
							$("#newFeedsDiv").html(
									"<a href='javascript:Feed.showNewFeeds();'>"
											+ Feed.newFeedsNum + "条新鲜事</a>");
							var innerHTML = "";
							for ( var i = 0; i < result.length; i++) {
								innerHTML += Feed.genFeed(result[i]);
							}
							$("#newFeedsContentDiv")[0].innerHTML = innerHTML
									+ $("#newFeedsContentDiv")[0].innerHTML;
						}
					},
					error : function() {
						// jAlert("对不起,获取新鲜事失败。", '新鲜事');
						$("#feedMessage").html(
								"<font color='red'>对不起,获取新鲜事失败。</font>");
					}
				});
	},
	showNewFeeds : function() {
		Feed.newFeedsNum = 0;
		$("#newFeedsDiv").html("");

		$("#feedsDiv")[0].innerHTML = $("#newFeedsContentDiv")[0].innerHTML
				+ $("#feedsDiv")[0].innerHTML;
		$("#newFeedsContentDiv").html("");
	}
}
